/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgStoryNpc
    {
        private readonly Dictionary<int, CfgStoryNpc> _dataMap;
        private readonly List<CfgStoryNpc> _dataList;


        public TbCfgStoryNpc(ByteBuf _buf)
        {
            //first read common data
            _TbCommonStoryNpc _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonStoryNpc(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgStoryNpc>(size * 3 / 2);
            _dataList = new List<CfgStoryNpc>(size);

            for (int i = 0; i < size; i++)
            {
                CfgStoryNpc _v;
                _v = CfgStoryNpc.DeserializeCfgStoryNpc(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgStoryNpc> DataMap => _dataMap;
        public IReadOnlyList<CfgStoryNpc> DataList => _dataList;

        public CfgStoryNpc Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgStoryNpc] config not found,id:" + key.ToString());

            return null;
        }

        public CfgStoryNpc GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "storynpc";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgStoryNpc LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgStoryNpc(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgStoryNpc
    {
        private CfgStoryNpc(ByteBuf _buf, _TbCommonStoryNpc _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Desc = TableCenter.GetI18NText(_buf.ReadInt());
            EntityType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; EntityAsset = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; WidgetEntityAsset = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Image = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Live2D = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Spine = _commonData._field4[dataIndex]; }

            PostInit();
        }

        internal static CfgStoryNpc DeserializeCfgStoryNpc(ByteBuf _buf, _TbCommonStoryNpc _commonData)
        {
            return new CfgStoryNpc(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Desc { get; private set; }
        /// <summary>
        /// 资源类型
        /// </summary>
        public int EntityType { get; private set; }
        /// <summary>
        /// 实体资源名
        /// </summary>
        public string EntityAsset { get; private set; }
        /// <summary>
        /// 挂件资源名
        /// </summary>
        public string WidgetEntityAsset { get; private set; }
        /// <summary>
        /// 英雄列表半身像图片资源路径（Assets\Res\05_Images\Texture\UIHeroRes\UIHeroHalfBody）
        /// </summary>
        public string Image { get; private set; }
        /// <summary>
        /// Live2D
        /// </summary>
        public string Live2D { get; private set; }
        /// <summary>
        /// Spine
        /// </summary>
        public string Spine { get; private set; }

        /// <summary>
        /// HeroHalfBodyImage 资源全路径
        /// </summary>
        public string Image_fullPath => $"Res/05_Images/Texture/UIHeroRes/UIHeroHalfBody/{Image}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonStoryNpc
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<string> _field4 { get; private set; }
        internal _TbCommonStoryNpc(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
